home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / preloaders / Preloader.as < prev   
Text File  |  2009-02-12  |  9KB  |  245 lines

  1. package mx.preloaders
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.LoaderInfo;
  5.    import flash.display.MovieClip;
  6.    import flash.display.Sprite;
  7.    import flash.events.ErrorEvent;
  8.    import flash.events.Event;
  9.    import flash.events.IEventDispatcher;
  10.    import flash.events.IOErrorEvent;
  11.    import flash.events.ProgressEvent;
  12.    import flash.events.TimerEvent;
  13.    import flash.utils.Timer;
  14.    import mx.core.RSLItem;
  15.    import mx.core.RSLListLoader;
  16.    import mx.core.ResourceModuleRSLItem;
  17.    import mx.core.mx_internal;
  18.    import mx.events.FlexEvent;
  19.    import mx.events.RSLEvent;
  20.    
  21.    use namespace mx_internal;
  22.    
  23.    public class Preloader extends Sprite
  24.    {
  25.       
  26.       mx_internal static const VERSION:String = "3.0.0.0";
  27.        
  28.       
  29.       private var app:IEventDispatcher = null;
  30.       
  31.       private var showDisplay:Boolean;
  32.       
  33.       private var timer:Timer;
  34.       
  35.       private var rslDone:Boolean = false;
  36.       
  37.       private var displayClass:IPreloaderDisplay = null;
  38.       
  39.       private var rslListLoader:RSLListLoader;
  40.       
  41.       public function Preloader()
  42.       {
  43.          super();
  44.       }
  45.       
  46.       private function getByteValues() : Object
  47.       {
  48.          var _loc1_:LoaderInfo = root.loaderInfo;
  49.          var _loc2_:int = _loc1_.bytesLoaded;
  50.          var _loc3_:int = _loc1_.bytesTotal;
  51.          var _loc4_:int = !!rslListLoader ? int(rslListLoader.getItemCount()) : 0;
  52.          var _loc5_:int = 0;
  53.          while(_loc5_ < _loc4_)
  54.          {
  55.             _loc2_ += rslListLoader.getItem(_loc5_).loaded;
  56.             _loc3_ += rslListLoader.getItem(_loc5_).total;
  57.             _loc5_++;
  58.          }
  59.          return {
  60.             "loaded":_loc2_,
  61.             "total":_loc3_
  62.          };
  63.       }
  64.       
  65.       private function appProgressHandler(param1:Event) : void
  66.       {
  67.          dispatchEvent(new FlexEvent(FlexEvent.INIT_PROGRESS));
  68.       }
  69.       
  70.       private function dispatchAppEndEvent(param1:Object = null) : void
  71.       {
  72.          dispatchEvent(new FlexEvent(FlexEvent.INIT_COMPLETE));
  73.          if(!showDisplay)
  74.          {
  75.             displayClassCompleteHandler(null);
  76.          }
  77.       }
  78.       
  79.       private function ioErrorHandler(param1:IOErrorEvent) : void
  80.       {
  81.       }
  82.       
  83.       private function appCreationCompleteHandler(param1:FlexEvent) : void
  84.       {
  85.          dispatchAppEndEvent();
  86.       }
  87.       
  88.       mx_internal function rslErrorHandler(param1:ErrorEvent) : void
  89.       {
  90.          var _loc2_:int = rslListLoader.getIndex();
  91.          var _loc3_:RSLItem = rslListLoader.getItem(_loc2_);
  92.          var _loc4_:RSLEvent;
  93.          (_loc4_ = new RSLEvent(RSLEvent.RSL_ERROR)).bytesLoaded = 0;
  94.          _loc4_.bytesTotal = 0;
  95.          _loc4_.rslIndex = _loc2_;
  96.          _loc4_.rslTotal = rslListLoader.getItemCount();
  97.          _loc4_.url = _loc3_.urlRequest;
  98.          _loc4_.errorText = decodeURI(param1.text);
  99.          dispatchEvent(_loc4_);
  100.       }
  101.       
  102.       public function initialize(param1:Boolean, param2:Class, param3:uint, param4:Number, param5:Object, param6:String, param7:Number, param8:Number, param9:Array = null, param10:Array = null, param11:Array = null, param12:Array = null) : void
  103.       {
  104.          var _loc13_:int = 0;
  105.          var _loc14_:int = 0;
  106.          var _loc15_:RSLItem = null;
  107.          var _loc16_:ResourceModuleRSLItem = null;
  108.          if((param9 != null || param10 != null) && param11 != null)
  109.          {
  110.             throw new Error("RSLs may only be specified by using libs and sizes or rslList, not both.");
  111.          }
  112.          root.loaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
  113.          if(param9 && param9.length > 0)
  114.          {
  115.             if(param11 == null)
  116.             {
  117.                param11 = [];
  118.             }
  119.             _loc13_ = param9.length;
  120.             _loc14_ = 0;
  121.             while(_loc14_ < _loc13_)
  122.             {
  123.                _loc15_ = new RSLItem(param9[_loc14_]);
  124.                param11.push(_loc15_);
  125.                _loc14_++;
  126.             }
  127.          }
  128.          if(param12 && param12.length > 0)
  129.          {
  130.             _loc13_ = param12.length;
  131.             _loc14_ = 0;
  132.             while(_loc14_ < _loc13_)
  133.             {
  134.                _loc16_ = new ResourceModuleRSLItem(param12[_loc14_]);
  135.                param11.push(_loc16_);
  136.                _loc14_++;
  137.             }
  138.          }
  139.          rslListLoader = new RSLListLoader(param11);
  140.          this.showDisplay = param1;
  141.          timer = new Timer(10);
  142.          timer.addEventListener(TimerEvent.TIMER,timerHandler);
  143.          timer.start();
  144.          if(param1)
  145.          {
  146.             displayClass = new param2();
  147.             displayClass.addEventListener(Event.COMPLETE,displayClassCompleteHandler);
  148.             addChild(DisplayObject(displayClass));
  149.             displayClass.backgroundColor = param3;
  150.             displayClass.backgroundAlpha = param4;
  151.             displayClass.backgroundImage = param5;
  152.             displayClass.backgroundSize = param6;
  153.             displayClass.stageWidth = param7;
  154.             displayClass.stageHeight = param8;
  155.             displayClass.initialize();
  156.             displayClass.preloader = this;
  157.          }
  158.          if(rslListLoader.getItemCount() > 0)
  159.          {
  160.             rslListLoader.load(mx_internal::rslProgressHandler,mx_internal::rslCompleteHandler,mx_internal::rslErrorHandler,mx_internal::rslErrorHandler,mx_internal::rslErrorHandler);
  161.          }
  162.          else
  163.          {
  164.             rslDone = true;
  165.          }
  166.       }
  167.       
  168.       mx_internal function rslProgressHandler(param1:ProgressEvent) : void
  169.       {
  170.          var _loc2_:int = rslListLoader.getIndex();
  171.          var _loc3_:RSLItem = rslListLoader.getItem(_loc2_);
  172.          var _loc4_:RSLEvent;
  173.          (_loc4_ = new RSLEvent(RSLEvent.RSL_PROGRESS)).bytesLoaded = param1.bytesLoaded;
  174.          _loc4_.bytesTotal = param1.bytesTotal;
  175.          _loc4_.rslIndex = _loc2_;
  176.          _loc4_.rslTotal = rslListLoader.getItemCount();
  177.          _loc4_.url = _loc3_.urlRequest;
  178.          dispatchEvent(_loc4_);
  179.       }
  180.       
  181.       public function registerApplication(param1:IEventDispatcher) : void
  182.       {
  183.          param1.addEventListener("validatePropertiesComplete",appProgressHandler);
  184.          param1.addEventListener("validateSizeComplete",appProgressHandler);
  185.          param1.addEventListener("validateDisplayListComplete",appProgressHandler);
  186.          param1.addEventListener(FlexEvent.CREATION_COMPLETE,appCreationCompleteHandler);
  187.          this.app = param1;
  188.       }
  189.       
  190.       mx_internal function rslCompleteHandler(param1:Event) : void
  191.       {
  192.          var _loc2_:int = rslListLoader.getIndex();
  193.          var _loc3_:RSLItem = rslListLoader.getItem(_loc2_);
  194.          var _loc4_:RSLEvent;
  195.          (_loc4_ = new RSLEvent(RSLEvent.RSL_COMPLETE)).bytesLoaded = _loc3_.total;
  196.          _loc4_.bytesTotal = _loc3_.total;
  197.          _loc4_.rslIndex = _loc2_;
  198.          _loc4_.rslTotal = rslListLoader.getItemCount();
  199.          _loc4_.url = _loc3_.urlRequest;
  200.          dispatchEvent(_loc4_);
  201.          rslDone = _loc2_ + 1 == _loc4_.rslTotal;
  202.       }
  203.       
  204.       private function timerHandler(param1:TimerEvent) : void
  205.       {
  206.          if(!root)
  207.          {
  208.             return;
  209.          }
  210.          var _loc2_:Object = getByteValues();
  211.          var _loc3_:int = _loc2_.loaded;
  212.          var _loc4_:int = _loc2_.total;
  213.          dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS,false,false,_loc3_,_loc4_));
  214.          if(rslDone && (_loc3_ >= _loc4_ && _loc4_ > 0 || _loc4_ == 0 && _loc3_ > 0 || root is MovieClip && MovieClip(root).totalFrames > 2 && MovieClip(root).framesLoaded >= 2))
  215.          {
  216.             timer.removeEventListener(TimerEvent.TIMER,timerHandler);
  217.             timer.reset();
  218.             dispatchEvent(new Event(Event.COMPLETE));
  219.             dispatchEvent(new FlexEvent(FlexEvent.INIT_PROGRESS));
  220.          }
  221.       }
  222.       
  223.       private function displayClassCompleteHandler(param1:Event) : void
  224.       {
  225.          if(displayClass)
  226.          {
  227.             displayClass.removeEventListener(Event.COMPLETE,displayClassCompleteHandler);
  228.          }
  229.          if(root)
  230.          {
  231.             root.loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
  232.          }
  233.          if(app)
  234.          {
  235.             app.removeEventListener("validatePropertiesComplete",appProgressHandler);
  236.             app.removeEventListener("validateSizeComplete",appProgressHandler);
  237.             app.removeEventListener("validateDisplayListComplete",appProgressHandler);
  238.             app.removeEventListener(FlexEvent.CREATION_COMPLETE,appCreationCompleteHandler);
  239.             app = null;
  240.          }
  241.          dispatchEvent(new FlexEvent(FlexEvent.PRELOADER_DONE));
  242.       }
  243.    }
  244. }
  245.